var BSTMG = BSTMG || {};
BSTMG.userManager = {
	init: function(){
		var that = this;
		//分页功能
		that.showUserList("");
		//右键菜单功能
		that.rightMenu();
		//根据登录号查询
		that.query();
	},
	showUserList: function(userName){
		var url="/sysAdmin/userAdmin/userList/search?userName="+userName;
		BSTMG.common.hjhPages(url,function(data){
			var userList = data.userList;
            var $tbody = $("#userList tbody"),
                html = '';
            if (userList.length > 0) {
                for (var i = 0; i < userList.length; i++) {
                    var userInfo = userList[i];
                    var accountMoney = setAccountMoney(userInfo);
                    var loginNum = setLoginNum(userInfo);
                    html += '<tr class="odd">';
                    html += '<td data-id="'+userInfo.userId+'">'+(i+1)+'</td>';
                    html += '<td>' + BSTMG.tools.checkNull(loginNum) + '</td>';
                    html += '<td>' + BSTMG.tools.checkNull(toDate(userInfo.addTime, "yyyy-MM-dd hh:mm:ss")) + '</td>';
                    html += '<td>' + BSTMG.tools.checkNull(userInfo.realName) + '</td>';
                    html += '<td>' + BSTMG.tools.checkNull(userInfo.phone) + '</td>';
                    html += '<td>' + parseFloat(accountMoney).toFixed(2) + '</td>';
                    html += '<td>' + BSTMG.tools.checkNull(userInfo.belongCompanyName) + '</td>';
                    html += '<td>' + BSTMG.tools.checkNull(userInfo.provinceCodeName) + BSTMG.tools.checkNull(userInfo.cityCodeName) + BSTMG.tools.checkNull(userInfo.areaCodeName) + BSTMG.tools.checkNull(userInfo.address) + '</td>';
//                    html += '<td><a class="btn btn-primary" href="/userAdmin/userDetail/' + userInfo.userId + '">查看详情</a>';
//                    html += '<a class="btn btn-primary" href="/userAdmin/userCompList/' + userInfo.userId + '">注册列表</a>';
                    html += '</td></tr>';
                }
                $tbody.html(html);
            } else {
                var $tr = '<tr class="odd"><td colspan="9">暂无数据！</td></tr>';
                $tbody.html($tr);
            }
		});
	},
	query : function(){
		$('#query').on('click',function(){
			var userName = $('#userName').val();
			BSTMG.userManager.showUserList(userName);
		})
	},
	rightMenu: function(){
		var $userList = $("#userList");
		BSTMG.plugins.kittyMenu();
		$userList.kittyMenu([{
			"menuname":"查看详情",
			"className": "btn-primary",
			"clickaction": function(event){	 //此事件为当前右键菜单事件
				var $this = $(event.target).parent("tr");		//当前选中的行
				var userId = $this.find("td").eq(0).attr("data-id");
				location.href = "/sysAdmin/userAdmin/userDetail/"+userId;
			}
		},{
			"menuname":"注册账户",
			"className": "btn-success",
			"clickaction": function(event){
				var $this = $(event.target).parent("tr");		//当前选中的行
				var userId = $this.find("td").eq(0).attr("data-id");
				location.href = "/sysAdmin/userAdmin/userCompList/"+userId;
			}
		}]);
		// 清除第一行右键菜单功能呢过
		$userList.find("tr:first-child").on("contextmenu",function(){
			return false;
		});
	}
}

$(function(){
	BSTMG.userManager.init();
});
//回车键查询功能
function keyQuery(){
	if(event.keyCode == 13){
		$('#query').trigger("click");
	}
}
//设置登陆账号
function setLoginNum(userInfo){
	if(userInfo.userEmail != "" && userInfo.userEmail != null){
		return userInfo.userEmail;
	}else if(userInfo.userTel != "" && userInfo.userTel != null){
		return userInfo.userTel;
	}else{
		return "";
	}
}

function setAccountMoney(userInfo){
	if(userInfo.accountMoney != "" && userInfo.accountMoney != null){
		return userInfo.accountMoney;
	}else{
		return 0.00;
	}
}





